package agent

import (
	"context"
)

// DeepSeekMessage DeepSeek消息格式（避免循环导入）
type DeepSeekMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

// LLMServiceInterface LLM服务接口（避免循环导入）
type LLMServiceInterface interface {
	GenerateResponse(ctx context.Context, messages []DeepSeekMessage) (string, error)
	GenerateStreamResponse(ctx context.Context, messages []DeepSeekMessage, responseChan chan<- string) error
}

// LLMAdapter LLM服务适配器
type LLMAdapter struct {
	llmService LLMServiceInterface
}

// NewLLMAdapter 创建新的LLM适配器
func NewLLMAdapter(llmService LLMServiceInterface) *LLMAdapter {
	return &LLMAdapter{
		llmService: llmService,
	}
}

// GenerateResponse 生成回复
func (adapter *LLMAdapter) GenerateResponse(ctx context.Context, messages []LLMMessage) (string, error) {
	// 转换消息格式
	deepSeekMessages := make([]DeepSeekMessage, len(messages))
	for i, msg := range messages {
		deepSeekMessages[i] = DeepSeekMessage{
			Role:    msg.Role,
			Content: msg.Content,
		}
	}

	// 调用原有的LLM服务
	return adapter.llmService.GenerateResponse(ctx, deepSeekMessages)
}

// GenerateStreamResponse 生成流式回复
func (adapter *LLMAdapter) GenerateStreamResponse(ctx context.Context, messages []LLMMessage, responseChan chan<- string) error {
	// 转换消息格式
	deepSeekMessages := make([]DeepSeekMessage, len(messages))
	for i, msg := range messages {
		deepSeekMessages[i] = DeepSeekMessage{
			Role:    msg.Role,
			Content: msg.Content,
		}
	}

	// 调用原有的LLM服务
	return adapter.llmService.GenerateStreamResponse(ctx, deepSeekMessages, responseChan)
}
